<?php

namespace IDock\Insurance\ZSIC\Request;

use IDock\Insurance\ZSIC\Request\AllZSICRequest;
use IDock\Insurance\ZSIC\Response\UploadFileResponse;
use IDock\Insurance\ZSIC\Response\VehicleModelResponse;
use IDock\Insurance\ZSIC\ZSICEnums;
use IDock\Visitor\UploadFileVisitor;
use IDock\Visitor\VehicleModelVisitor;

/**
 * 图片上传
 */
class UploadFileRequest extends AllZSICRequest
{
    protected $response = UploadFileResponse::class;

    protected $urlTip = '影像资料上传';

//    protected $inLog = false;

    public $requestCode = 'documentUpload';

    /**
     * @var UploadFileVisitor $visitor
     */
    protected $visitor;

    public function generate(): array
    {
        $this->channelCode = $this->visitor->argc['channelCode'] ?? '';
        $this->cityCode = $this->visitor->argc['cityCode'] ?? '';

        return [
            'base' => [
                'referenceNo' => $this->visitor->argc['quotationNo'] ?? '',
                'orderNo' => $this->visitor->argc['orderNo'] ?? '',
                'vciProposalNo' => $this->visitor->argc['vciProposalNo'] ?? '',
                'tciProposalNo' => $this->visitor->argc['tciProposalNo'] ?? '',
            ],
            'files' => $this->getFile()
        ];
    }

    public function getFile()
    {
        $list = [];
        foreach ($this->visitor->fileList as $value) {
            $fixArr = explode('.', $value['url'] ?? '');
            $fix = end($fixArr);
            if($fix == 'jpeg'){
                $fix = 'jpg';
            }
            $fileName = $value['url'] ?? '';
            $fileNameArr = explode('/',$fileName);
            $tmp = [
                'fileName' => $value['url'] ?? '',
                'finalFileName' => end($fileNameArr),
                'fileType' => $fix,
                'documentType' => ZSICEnums::$uploadImageType[$value['type'] ?? ''] ?? '',
            ];
            $list[] = $tmp;
            unset($tmp);
        }
        return ['file' => $list];
    }

    public function getBusinessNo()
    {
        return $this->visitor->argc['businessNo'] ?? '';
    }
}
